#ifdef USE_LCD_TFT
//
// Created by gastonfeng on 2022/8/21.
//

#include "base/timer.h"
#include "base/enums.h"
#include "widgets/button.h"
#include "widgets/image.h"
#include "widgets/label.h"
#include "base/window.h"
#include "widgets/slider.h"
#include "widgets/group_box.h"
#include "widgets/check_button.h"
#include "widgets/progress_bar.h"

#include "lcd_tft.h"

int lcd_tft::begin(uint32_t tick) {
    widget_t *image = NULL;
    widget_t *ok = NULL;
    widget_t *label = NULL;
    widget_t *cancel = NULL;
    widget_t *slider = NULL;
    widget_t *progress_bar = NULL;
    widget_t *check_button = NULL;
    widget_t *radio_button = NULL;
    widget_t *show_dialog = NULL;
    widget_t *group_box = NULL;
    widget_t *win = window_create(NULL, 0, 0, 0, 0);

    ok = button_create(win, 10, 5, 80, 30);
    widget_set_text(ok, L"Inc");

    cancel = button_create(win, 100, 5, 80, 30);
    widget_set_text(cancel, L"Dec");

    show_dialog = button_create(win, 190, 5, 80, 30);
    widget_set_text(show_dialog, L"Dialog");

    image = image_create(win, 10, 230, 100, 100);
    image_set_image(image, "earth");
    image_set_draw_type(image, IMAGE_DRAW_ICON);

    image = image_create(win, 100, 230, 100, 100);
    image_set_image(image, "earth");
    image_set_draw_type(image, IMAGE_DRAW_SCALE);

    image = image_create(win, 10, 360, 100, 100);
    image_set_image(image, "bricks");
    image_set_draw_type(image, IMAGE_DRAW_ICON);

    image = image_create(win, 100, 360, 100, 100);
    image_set_image(image, "bricks");
    image_set_draw_type(image, IMAGE_DRAW_SCALE);

    label = label_create(win, 10, 40, 80, 30);
    widget_set_text(label, L"Left");
    widget_use_style(label, "left");

    label = label_create(win, 100, 40, 80, 30);
    widget_set_text(label, L"C enter");
#ifdef WITH_STB_FONT
    widget_use_style(label, "center");
#else
    widget_use_style(label, "center-ap");
#endif

    label = label_create(win, 190, 40, 80, 30);
    widget_set_text(label, L"Right");
    widget_use_style(label, "right");

    progress_bar = progress_bar_create(win, 10, 80, 168, 20);
    widget_set_value(progress_bar, 40);
//    timer_add(on_timer, progress_bar, 500);

#ifdef WITH_STB_FONT
    progress_bar_set_show_text(progress_bar, TRUE);
#endif

    slider = slider_create(win, 10, 105, 168, 20);
    widget_set_value(slider, 40);

    progress_bar = progress_bar_create(win, 260, 80, 20, 118);
    widget_set_value(progress_bar, 40);
    progress_bar_set_vertical(progress_bar, TRUE);
//    timer_add(on_timer, progress_bar, 500);

    slider = slider_create(win, 230, 80, 20, 118);
    widget_set_value(slider, 40);
    slider_set_vertical(slider, TRUE);

//    widget_on(ok, EVT_CLICK, on_inc, progress_bar);
//    widget_on(cancel, EVT_CLICK, on_dec, progress_bar);
//    widget_on(show_dialog, EVT_CLICK, on_show_dialog, NULL);

    check_button = check_button_create(win, 10, 150, 80, 30);
    widget_set_text(check_button, L"Book");

    check_button = check_button_create(win, 100, 150, 80, 30);
    widget_set_text(check_button, L"Food");

    radio_button = check_button_create_radio(win, 10, 200, 80, 30);
    widget_set_text(radio_button, L"Book");

    radio_button = check_button_create_radio(win, 100, 200, 80, 30);
    widget_set_text(radio_button, L"Food");

    radio_button = check_button_create_radio(win, 190, 200, 80, 30);
    widget_set_text(radio_button, L"Pencil");
    widget_set_value(radio_button, TRUE);

    group_box = group_box_create(win, 10, 300, 32 * 3, 32);
    widget_use_style(group_box, "box");
    radio_button = check_button_create_radio(group_box, 0, 0, 32, 32);
    widget_use_style(radio_button, "left");
    radio_button = check_button_create_radio(group_box, 32, 0, 32, 32);
    widget_use_style(radio_button, "middle");
    radio_button = check_button_create_radio(group_box, 64, 0, 32, 32);
    widget_use_style(radio_button, "right");

    check_button = check_button_create(win, 108, 300, 32, 32);
    widget_use_style(check_button, "mute");

    return 0;
}

int lcd_tft::run(uint32_t tick) {
    return 0;
}
#ifdef __PLATFORMIO_BUILD_DEBUG__
int lcd_tft::dev_test(uint32_t tick) {
    return 0;
}
#endif
int lcd_tft::diag(uint32_t tick) {
    return 0;
}

lcd_tft lcd;
#endif
